package super

import (
	"Project/global"
	"Project/model/drugs"
	"Project/model/drugs/response"
)

type DrugShopService struct{}

func (d *DrugShopService) DrugShopList() ([]response.DrugShopRecord, error) {
	// 获取药店id
	var drugsShopId []int64
	var data []response.DrugShopRecord
	if err := global.GVA_DB.Debug().Model(&drugs.DrugsShop{}).Select("drugs_shop_id").Find(&drugsShopId).Error; err != nil {
		return nil, err
	}
	// 从销售人员表中，通过表连接 查获取到所有负责人，将数据放入到最终结果list中
	if err := global.GVA_DB.Debug().Model(&drugs.DrugsShop{}).
		Select([]string{"drugs_shop_id", "area_id", "name", "register_addr", "credit_code", "user_sale.user_name", "card", "phone"}).
		Joins("left join user_sale on drugs_shop.drugs_shop_id = user_sale.shop_id").
		Find(&data, "shop_keeper=? and shop_id in ?", true, drugsShopId).Error; err != nil {
		return nil, err
	}
	return data, nil
}
